import { BehaviourNode } from "./BehaviorNode";
import { RunStatus } from "./IBehaviourTree";

export interface data {
    [key: string]: any
}

export class BehaviorTree {
    static debug = false;
    root: BehaviourNode;
    status: RunStatus = RunStatus.Completed;
    tickIntervalId: number = 0;
    frame: number = 1
    tickStepTime: number = 1 / 60;
    canTick: boolean = false;
    constructor(root: BehaviourNode) {
        this.root = root;
        this.canTick = true;
    }
    async Tick(): Promise<any> {
        // if (this.status == RunStatus.Running) {
        //     this.status = BehaviorTree.runningNode.Tick();
        //     debugger
        // } else {
        if (!this.canTick) return
        // console.log('tick2',this.status == RunStatus.Running)
        if (this.status == RunStatus.Running) {
            return;
        }
        if (BehaviorTree.debug)
            console.log('-----------------tick1----------------')
        this.status = RunStatus.Running;
        this.status = await this.root.Tick();
        if (BehaviorTree.debug)
            console.log('tick3', this.status)
        // }
        return this.status;
    }
}
